﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Api
{
    class SendMessageToUserAction : AuthPostAction<Params.SendMessageToUserParams,
        Results.SendMessageToUserResult>
    {
        protected override ActionResult<Results.SendMessageToUserResult> OnExecute(ActionContext context, SysParameters sysParameters,
            Params.SendMessageToUserParams opParams)
        {
            ServiceResult<Message> serviceResult = new MessageService().SendToUser(context.AccountId,
                opParams.TargetUserId,
                opParams.Content);

            Results.SendMessageToUserResult actionResult = new Results.SendMessageToUserResult();

            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {
                return new ActionResult<Results.SendMessageToUserResult>(true, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            return new ActionResult<Results.SendMessageToUserResult>(false, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }
}
